﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using K9Nano.IM.Models;
using K9Nano.LayIM;
using K9Nano.LayIM.Events;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using WalkingTec.Mvvm.Core;

namespace K9Nano.IM.LayIM
{
    public class ChatGroupProvider : ChatStoreBase, IChatGroupProvider
    {
        public ChatGroupProvider(IDataContext db, IOptions<LayIMOptions> options) : base(db, options)
        {
        }

        public async ValueTask<IEnumerable<string>> GetGroupsAsync(OnlineNotification online)
        {
            Guid.TryParse(online.UserId, out var uid);

            var staff = await Db.Set<ChatRoomMember>()
                .Where(x => x.MemberId == uid)
                .Select(x => x.RoomId)
                .ToListAsync();

            return staff.Select(x => x.ToString()).ToList();
        }
    }
}